package com.kizitonwose.calendarview.utils;

/**
 * Kotlin中String的方法
 *
 * @author LiuQingHua
 * @version 1.0
 * @date 2021/2/22 9:57
 */
public class StringExtension {
    private String string;

    private StringExtension(String string) {
        if (string == null) {
            string = "";
        }
        this.string = string;

    }

    public String getString() {
        return string;
    }

    public static StringExtension getInstance(String string) {
        return new StringExtension(string);
    }

    public StringExtension ifEmpty(String defaultValue) {
        string = (string == null ? "null" : string.length() == 0 ? defaultValue : string);
        return this;
    }

    /**
     * 是否是空白字符
     * Determines whether a character is whitespace according to the Unicode standard.
     * * Returns `true` if the character is whitespace.
     *
     * @return
     */
    public boolean isBlank() {
        if (string.length() == 0) return true;
        char[] chars = string.toCharArray();
        for (char aChar : chars) {
            if (!(Character.isWhitespace(aChar) || Character.isSpaceChar(aChar))) {
                return false;
            }
        }
        return true;
    }


}
